package com.sf.wisdomkg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sf.wisdomkg.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Administrator on 2017/8/29.
 */
public class PopupWindowListViewAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<HashMap<String, String>> list;

    private int width;
    public static int selectIndex_FangXing;//房型
    public static int selectIndex_JiaGe;//价格
    public static int selectIndex_JingQu;//景区


    public PopupWindowListViewAdapter(Context context, ArrayList<HashMap<String,String>> data_list) {
        this.context = context;
        this.list = data_list;

        this.width = width;

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    public View getView(int position, View convertView, ViewGroup arg2) {
        // TODO Auto-generated method stub
        LayoutInflater inflater = LayoutInflater.from(context);
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.home_banji_dropdown_list_item,null);
            viewHolder.dropdown= (TextView) convertView.findViewById(R.id.dropdown);
            viewHolder.item_parent = (LinearLayout)convertView.findViewById(R.id.item_parent);
            viewHolder.line = (View)convertView.findViewById(R.id.line);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.dropdown.setText(list.get(position).get("name"));

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        //此处相当于布局文件中的Android:layout_gravity属性

        if( selectIndex_FangXing == position ){
            viewHolder.dropdown.setTextColor(context.getResources().getColor(R.color.content_org_color));
            viewHolder.item_parent.setBackgroundColor(context.getResources().getColor(R.color.white));
        }else{
            viewHolder.dropdown.setTextColor(context.getResources().getColor(R.color.black));
            viewHolder.item_parent.setBackgroundColor(context.getResources().getColor(R.color.bg_grey));
        }


        viewHolder.dropdown.setLayoutParams(lp);
        if (list.size() == (position+1)){
            viewHolder.line.setVisibility(View.VISIBLE);
        }else {
            viewHolder.line.setVisibility(View.GONE);
        }
        return convertView;
    }
    public class ViewHolder{
        TextView dropdown;
        private LinearLayout item_parent;
        View line;

    }
}
